﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Common;
using Utility;

namespace School.UserCentents
{
    public partial class Article : UserCheckPower
    {
        #region 分页相关

        //获取传入当前页码
        int PageIndex
        {
            get
            {
                if (Request.QueryString.Get("page") != null)
                {
                    if (!Common.TypeValidator.IsNumeric(Request.QueryString.Get("page")))
                    {
                        return 1;
                    }
                    return Convert.ToInt32(Request.QueryString.Get("page"));
                }
                return 1;
            }
        }

        //分页数
        private int PageSize
        {
            get
            {
                return 5;
            }
        }
        #endregion
        BLL.WenZhang w = new BLL.WenZhang();
        BLL.Users Users = new BLL.Users();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PageLoad();
            }
        }

        private void PageLoad()
        {
            Model.Users u = new BLL.Users().GetModel(LoginUserId);
            string strWhere = " and UserID=" + LoginUserId;
            DataSet ds = w.GetList("UserID=" + LoginUserId);
            if (u.UserTypeID == 1)
            {
                strWhere = "";
                ds = w.GetList("");
            }
            else if (u.UserTypeID == 2)
            {
                strWhere = " and UserID in(select ID from Users where Remark =" + LoginUserId + ")";
                ds = w.GetList("UserID in(select ID from Users where Remark =" + LoginUserId + ")");
            }
            else if (u.UserTypeID == 3)
            {
                strWhere = " and UserID in(select ID from Users where Remark2 =" + LoginUserId + ")";
                ds = w.GetList("UserID in(select ID from Users where Remark2 =" + LoginUserId + ")");
            }
            else if (u.UserTypeID == 4)
            {
                if (Session["ClassID"] != null)
                {
                    strWhere = " and UserID in(select ID from ClassPersonnel where ClassID=" + Session["ClassID"] + " and Manager=0)";
                    ds = w.GetList("UserID in(select ID from ClassPersonnel where ClassID=" + Session["ClassID"] + " and Manager=0)");
                }
            }

            Repeater1.DataSource = w.GetList(PageSize, PageIndex, strWhere);
            Repeater1.DataBind();
            AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
            AspNetPager1.PageSize = 5;
            AspNetPager1.CurrentPageIndex = PageIndex;
            AspNetPager1.DataBind();
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
            }
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.Equals("del",StringComparison.CurrentCultureIgnoreCase))
            {
                if (w.Delete(MyCommon.ConvertToInt(e.CommandArgument)))
                {
                    ScriptHelper.AlertRedirect("删除文章成功！", "Article.aspx");
                }
            }
        }
    }
}